package com.MapJiHe;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class MapProvinceAndCity {
    public static void main(String[] args) {
        List<String> names=new ArrayList<>();
        Collections.addAll(names,"张无忌","张三丰","周芷若","赵敏","张强");
        Stream<String> stream = names.stream();//List类集合的Stream流的获取。
        System.out.println(names);
        List<String>list=new ArrayList<>();
        //找出姓张的且名字是三个字的。
        for (String name : names) {
            if(name.startsWith("张")&&name.length()==3){
                list.add(name);
            }
        }
        System.out.println(list);
        //Stream流进行检索//Collection提供的方法所以只能Collection的子类调用二Map类不能调用
       List<String>list2=names.stream().filter(a->a.startsWith("张")).filter(s->s.length()==3).collect(Collectors.toList());
        System.out.println(list2);
        //Stream的常见方法
        //Set类获取Stream流的方法
        Set<String>set=new HashSet<>();
        Stream<String> stream1 = set.stream();
        //Map集合的Stream流的获取
        Map<String,Double>map=new HashMap<>();
        Set<String>keys=map.keySet();
        Stream<String> stream2 = keys.stream();//获取简称为一个数组，再通过他得到Stream流
        Collection<Double>values=map.values();
        Stream<Double> stream3 = values.stream();
        //将map集合中的键值对看成一个整体元素；
        Set<Map.Entry<String, Double>> entries = map.entrySet();
        Stream<Map.Entry<String, Double>> stream4 = entries.stream();
        //数组获取Stream流
        String[]names2={"张翠山","东方不败","堂大山","独孤求败"};
        Stream<String> s1 = Arrays.stream(names2);
        Stream<String> s2 = Stream.of(names2);



    }
}
